package com.qqtech.qquan.push.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.qqtech.core.common.enums.YesNoEnum;
import com.qqtech.core.common.util.JsonUtil;
import com.qqtech.core.common.util.StringUtil;
import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.order.cache.OrderSysParamCache;
import com.qqtech.qquan.order.enums.OrderBaseDeliveryStatusSignTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderBaseOrderStatusCancelTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderBaseOrderTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderBasePayTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderBaseReturnStatusCompleteTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderConst;
import com.qqtech.qquan.order.enums.ReturnPayStatusAgreeTypeEnum;
import com.qqtech.qquan.order.model.OrderBase;
import com.qqtech.qquan.order.model.OrderSplit;
import com.qqtech.qquan.order.service.OrderBaseService;
import com.qqtech.qquan.order.service.OrderSplitService;
import com.qqtech.qquan.pub.cache.PubSysParamCache;
import com.qqtech.qquan.pub.enums.PubConst;
import com.qqtech.qquan.pub.enums.PubPlatformEnum;
import com.qqtech.qquan.pub.model.PubUpgrade;
import com.qqtech.qquan.pub.model.PubUpgradeContent;
import com.qqtech.qquan.pub.service.PubUpgradeService;
import com.qqtech.qquan.push.cache.PushSysParamCache;
import com.qqtech.qquan.push.dao.PushLogDao;
import com.qqtech.qquan.push.enums.PushBizzEnum;
import com.qqtech.qquan.push.enums.PushConst;
import com.qqtech.qquan.push.enums.PushTypeEnum;
import com.qqtech.qquan.push.model.PushAudience;
import com.qqtech.qquan.push.model.PushLog;
import com.qqtech.qquan.push.model.PushLogVo;
import com.qqtech.qquan.send.model.SendDeliveryUserOrder;
import com.qqtech.qquan.send.service.SendDeliveryUserOrderService;
import com.qqtech.qquan.user.enums.UserValueOsTypeDictEnum;
import com.qqtech.qquan.user.model.UserBase;
import com.qqtech.qquan.user.model.UserValue;
import com.qqtech.qquan.user.service.UserBaseService;
import com.qqtech.qquan.user.service.UserFriendService;
import com.qqtech.qquan.user.service.UserValueService;

@Service
public class PushBizzServiceImpl extends BaseServiceImpl<PushLog> implements PushBizzService {
	public static final Logger log = LoggerFactory.getLogger(PushBizzServiceImpl.class);

	@Resource
	private PushAudienceService pushAudienceService;
	@Resource
	private PushJgService pushJgService;
	@Resource
	private PushLogDao pushLogDao;
	@Resource
	private UserFriendService userFriendService;
	@Resource
	private UserBaseService userBaseService;
	@Resource
	private PubUpgradeService pubUpgradeService;
	@Resource
	private OrderBaseService orderBaseService;
	@Resource
	private OrderSysParamCache orderSysParamCache;
	@Resource
	private UserValueService userValueService;
	@Resource
	private PubSysParamCache pubSysParamCache;
	@Resource
	private OrderSplitService orderSplitService;

	@Resource
	private SendDeliveryUserOrderService sendDeliveryUserOrderService;
	@Resource
	private PushSysParamCache pushSysParamCache;

	@Override
	protected BaseDao<PushLog> getBaseDao() {
		return pushLogDao;
	}

	@Override
	public void adminNotice(String title, String msg, String url, Integer communityId) {
		if (StringUtil.isBlank(title) || StringUtil.isBlank(msg)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		if (communityId != null && communityId.intValue() != 0) {
			pushLogVo.setCommunityId(communityId);
			pushLogVo.setTags("" + communityId);
			List<String> tagValues = new ArrayList<String>(1);
			tagValues.add("" + communityId);
			pushLogVo.setTagValues(tagValues);
		}
		pushLogVo.setPushBizz(PushBizzEnum.SYS_ADMIN.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.SYS_ADMIN.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_TITLE, title.trim());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_MSG, msg.trim());
		if (StringUtil.isNotBlank(url)) {
			mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_URL, url);
		}
		pushLogVo.setTitle(title);
		pushLogVo.setAlert(title);
		pushLogVo.setMessage(msg);
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void honorNotice(Integer userId, String msg) {
		if (StringUtil.isBlank(msg)) {
			return;
		}
		if (userId == null || userId.intValue() == 0) {
			return;
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(userId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.HONOR_NOTICE_COMMON.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.HONOR_NOTICE_COMMON.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID, "" + userId);// 被推送的人的userId
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		pushLogVo.setTitle("圈圈荣誉系统通知");
		pushLogVo.setAlert(msg);
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void refuseReturnPay(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		String registrationId = pushAudienceService.getRegistrationIdByUserId(orderBase.getBuyerId());
		if (StringUtil.isBlank(registrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_RETURN_PAY_REFUSE.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		List<String> registrationIds = new ArrayList<String>(1);
		registrationIds.add(registrationId);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_RETURN_PAY_REFUSE.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		pushLogVo.setMapExtras(mapExtras);
		String tips = "卖家拒绝退款，可以保持继续沟通或者联系圈圈客服";
		pushLogVo.setTitle("拒绝退款通知");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		this.doPush(pushLogVo);
	}

	@Override
	public void returnPayed(String orderNo, ReturnPayStatusAgreeTypeEnum returnPayStatusAgreeTypeEnum) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		String registrationId = pushAudienceService.getRegistrationIdByUserId(orderBase.getBuyerId());
		if (StringUtil.isBlank(registrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_RETURN_PAY_AGREE.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		List<String> registrationIds = new ArrayList<String>(1);
		registrationIds.add(registrationId);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_RETURN_PAY_AGREE.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		pushLogVo.setMapExtras(mapExtras);
		String tips = "卖家同意退款，请留意订单和查收账户余额";
		if (!ReturnPayStatusAgreeTypeEnum.ADMIN.equals(returnPayStatusAgreeTypeEnum)) {
			tips = "圈圈平台同意退款，请留意订单和查收账户余额";
		}
		pushLogVo.setTitle("同意退款通知");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		this.doPush(pushLogVo);
	}

	@Override
	public void applyReturnPay(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<String> registrationIds = new ArrayList<String>();
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					String registrationId = pushAudienceService.getRegistrationIdByUserId(orderSplit2.getSellerId());
					if (StringUtil.isNotBlank(registrationId)) {
						registrationIds.add(registrationId);
					}
				}
			}
		}
		if (registrationIds == null || registrationIds.size() == 0) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_RETURN_PAY_APPLY.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_RETURN_PAY_APPLY.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		pushLogVo.setMapExtras(mapExtras);
		String nick = "";
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		pushLogVo.setTitle("申请退款通知");
		pushLogVo.setAlert("用户" + nick + "申请退款，请查看订单并及时处理");
		pushLogVo.setMessage("用户" + nick + "申请退款，请查看订单并及时处理");
		this.doPush(pushLogVo);
	}

	@Override
	public void beInvitedCircle(Integer beInvitedId, String circleName) {
		if (beInvitedId == null || beInvitedId.intValue() == 0) {
			return;
		}
		if (StringUtil.isBlank(circleName)) {
			circleName = "圈子";
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(beInvitedId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.USER_BEINVITED_CIRCLE.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USER_BEINVITED_CIRCLE.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_USER_BEINVITED_CIRCLENAME, "" + circleName);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID, "" + beInvitedId);// 被推送的人的userId
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		pushLogVo.setTitle("消息通知");
		pushLogVo.setAlert("有人邀请您加入圈子，请在圈圈的消息页面查看");
		pushLogVo.setMessage("有人邀请您加入圈子，请在圈圈的消息页面查看");
		pushLogVo.setUserIds(beInvitedId.toString());
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}

	@Override
	public void upgradeNative(PubPlatformEnum pubPlatformEnum) {
		PushLogVo pushLogVo = new PushLogVo();
		if (pubPlatformEnum == null) {
			pubPlatformEnum = PubPlatformEnum.ALL;
		}
		pushLogVo.setPlatform(pubPlatformEnum.getCode());
		pushLogVo.setPushBizz(PushBizzEnum.APP_UPGRADE_NATIVE.getCode());
		pushLogVo.setTimeToLive(86400);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.APP_UPGRADE_NATIVE.getCode());
		String content = pubSysParamCache.get(PubConst.PARAMKEY_PUB_UPGRADE_CONTENT);
		List<PubUpgradeContent> contentList = new ArrayList<PubUpgradeContent>(10);
		if (StringUtil.isNotBlank(content)) {
			String[] contentArr = content.split(";");
			if (contentArr != null && contentArr.length > 0) {
				int index = 1;
				for (String string : contentArr) {
					if (StringUtil.isBlank(string)) {
						continue;
					}
					PubUpgradeContent c = new PubUpgradeContent();
					c.setId(index);
					c.setContent(string.trim());
					contentList.add(c);
					index++;
				}
			}
		}
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_CONTENTLIST, JsonUtil.toJson(contentList));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_NATIVEVERSION,
				pubSysParamCache.get(PubConst.PARAMKEY_PUB_UPGRADE_NATIVE, "1.0.0"));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_WXZADDRESSANDROID, pubSysParamCache
				.get(PubConst.PARAMKEY_PUB_UPGRADE_MARKET_ANDROID, PubConst.DEFAULTVALUE_PUB_UPGRADE_WXZ));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_WXZADDRESSIOS,
				pubSysParamCache.get(PubConst.PARAMKEY_PUB_UPGRADE_MARKET_IOS, PubConst.DEFAULTVALUE_PUB_UPGRADE_WXZ));
		pushLogVo.setTitle("圈圈系统更新");
		pushLogVo.setAlert("圈圈发布重大更新");
		pushLogVo.setMessage("圈圈发布重大更新");
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void upgradeByVersion() {
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.APP_UPGRADE_BYVERSION.getCode());
		pushLogVo.setTimeToLive(86400);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.APP_UPGRADE_BYVERSION.getCode());
		pushLogVo.setTitle("圈圈系统更新");
		pushLogVo.setAlert("圈圈发布重大更新");
		pushLogVo.setMessage("圈圈发布重大更新");
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void communityAuth(Integer userId, YesNoEnum yesNo) {
		if (userId == null || userId.intValue() == 0 || yesNo == null) {
			return;
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(userId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.USER_COMMUNITYAUTH.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USER_COMMUNITYAUTH.getCode());
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		String content = "非常抱歉，您未通过社区住户认证";
		String status = "" + YesNoEnum.NO.getCode();
		if (YesNoEnum.YES.getCode() == yesNo.getCode()) {
			content = "恭喜，您已通过社区住户认证，谢谢支持！";
			status = "" + YesNoEnum.YES.getCode();
		}
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_STATUS, status);
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setTitle("社区认证通知");
		pushLogVo.setAlert(content);
		pushLogVo.setMessage(content);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}

	@Override
	public void realAuth(Integer userId, YesNoEnum yesNo) {
		if (userId == null || userId.intValue() == 0 || yesNo == null) {
			return;
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(userId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.USER_REALAUTH.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USER_REALAUTH.getCode());
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		String content = "非常抱歉，您的身份信息认证不通过";
		String status = "" + YesNoEnum.NO.getCode();
		if (YesNoEnum.YES.getCode() == yesNo.getCode()) {
			content = "恭喜，您的身份认证已通过审核，谢谢支持！";
			status = "" + YesNoEnum.YES.getCode();
		}
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_STATUS, status);
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setTitle("身份认证通知");
		pushLogVo.setAlert(content);
		pushLogVo.setMessage(content);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}

	@Override
	public void userOffWhenLoginOtherDevice(Integer userId, String registrationId) {
		if (StringUtil.isBlank(registrationId)) {
			return;
		}
		if (userId == null) {
			userId = 0;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.USER_STATUS_OFF.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USER_STATUS_OFF.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_USER_OFF_USERID, "" + userId);
		pushLogVo.setMapExtras(mapExtras);
		List<String> registrationIds = new ArrayList<String>(1);
		registrationIds.add(registrationId);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setTitle("下线通知");
		pushLogVo.setAlert("账号在其它手机上登陆，您被迫下线");
		pushLogVo.setMessage("账号在其它手机上登陆，您被迫下线");
		if (userId != null) {
			pushLogVo.setUserIds(userId.toString());
		}
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
		// 删除退出的推送id
		PushAudience pushAudience = new PushAudience();
		pushAudience.setUserId(userId);
		pushAudience.setRegistrationId(registrationId);
		pushAudienceService.delete(pushAudience);
	}

	@Override
	public void imNotifyWhenUserBg(Integer toUserId) {
		if (toUserId == null || toUserId.intValue() == 0) {
			return;
		}
		UserValue userValue = userValueService.getById(toUserId);
		if (userValue == null || userValue.getIsBackground() == null || userValue.getOsType() == null
				|| UserValueOsTypeDictEnum.ANDROID.getCode() != userValue.getOsType().intValue()
				|| YesNoEnum.YES.getCode() != userValue.getIsBackground().intValue()
				|| StringUtil.isBlank(userValue.getRegistrationId())) {
			return;
		}
		PushLog pushLogAll = new PushLog();
		pushLogAll.setPushBizz(PushBizzEnum.USER_IM_BGNOTIFY.getCode());
		pushLogAll.setUserIds(toUserId.toString());
		List<PushLog> historyList = pushLogDao.queryList(pushLogAll, new PageKit(new PageOrder(Direction.DESC, "id")));
		PushLogVo pushLogVo = new PushLogVo();
		if (historyList != null && historyList.size() > 0) {
			pushLogAll = historyList.get(0);
			if (pushLogAll != null && StringUtil.isNotBlank(pushLogAll.getMsgId())) {
				pushLogVo.setOverrideMsgId(pushLogAll.getMsgId());
			}
		}
		String registrationId = userValue.getRegistrationId();
		List<String> registrationIds = new ArrayList<String>(1);
		registrationIds.add(registrationId);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setPushBizz(PushBizzEnum.USER_IM_BGNOTIFY.getCode());
		pushLogVo.setTimeToLive(0);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USER_IM_BGNOTIFY.getCode());
		String tips = "您有新消息";
		pushLogVo.setTitle("圈圈生活");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setUserIds(toUserId.toString());
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}

	@Override
	public void upgradeAll() {
		PubUpgrade pubUpgrade = pubUpgradeService.getCachePubUpgrade();
		if (pubUpgrade == null || YesNoEnum.YES.getCode() != pubUpgrade.getIsUpgrade()) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		PushLog pushLogAll = new PushLog();
		pushLogAll.setPushBizz(PushBizzEnum.APP_UPGRADE_WHOLE.getCode());
		List<PushLog> historyList = pushLogDao.queryList(pushLogAll, new PageKit(new PageOrder(Direction.DESC, "id")));
		if (historyList != null && historyList.size() > 0) {
			pushLogAll = historyList.get(0);
			if (pushLogAll != null && StringUtil.isNotBlank(pushLogAll.getMsgId())) {
				pushLogVo.setOverrideMsgId(pushLogAll.getMsgId());
			}
		}
		pushLogVo.setPushBizz(PushBizzEnum.APP_UPGRADE_WHOLE.getCode());
		pushLogVo.setTimeToLive(86400);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.APP_UPGRADE.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_ANDROID,
				JsonUtil.toJson(pubUpgradeService.getUpgradeByPlatform(PubPlatformEnum.ANDROID.getCode())));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_IOS,
				JsonUtil.toJson(pubUpgradeService.getUpgradeByPlatform(PubPlatformEnum.IOS.getCode())));
		pushLogVo.setTitle("圈圈系统更新");
		pushLogVo.setAlert("圈圈发布重大更新");
		pushLogVo.setMessage("圈圈发布重大更新");
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void upgradeByRegistrationIds(List<String> registrationIds, String overrideMsgId) {
		if (registrationIds == null || registrationIds.size() == 0) {
			return;
		}
		PubUpgrade pubUpgrade = pubUpgradeService.getCachePubUpgrade();
		if (pubUpgrade == null || YesNoEnum.YES.getCode() != pubUpgrade.getIsUpgrade()) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		if (StringUtil.isNotBlank(overrideMsgId)) {
			pushLogVo.setOverrideMsgId(overrideMsgId);
		}
		pushLogVo.setPushBizz(PushBizzEnum.APP_UPGRADE_UPDATE.getCode());
		pushLogVo.setTimeToLive(86400);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.APP_UPGRADE.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_ANDROID,
				JsonUtil.toJson(pubUpgradeService.getUpgradeByPlatform(PubPlatformEnum.ANDROID.getCode())));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHPUBUPGRADE_IOS,
				JsonUtil.toJson(pubUpgradeService.getUpgradeByPlatform(PubPlatformEnum.IOS.getCode())));
		pushLogVo.setTitle("圈圈系统更新");
		pushLogVo.setAlert("圈圈发布重大更新");
		pushLogVo.setMessage("圈圈发布重大更新");
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}

	@Override
	public void orderSelected(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);

		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<String> registrationIds = new ArrayList<String>();
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					String registrationId = pushAudienceService.getRegistrationIdByUserId(orderSplit2.getSellerId());
					if (StringUtil.isNotBlank(registrationId)) {
						registrationIds.add(registrationId);
					}
				}
			}
		}

		if (registrationIds == null || registrationIds.size() == 0 || orderBase == null) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_SELECTED.getCode());
		pushLogVo.setTimeToLive(orderSysParamCache.getInt(OrderConst.DICTYPE_ORDER_ONLINE_PAY_AUTO_EXPIRE_MINS) * 60);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_SELECTED.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		pushLogVo.setMapExtras(mapExtras);
		String nick = "";
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String tips = "用户" + nick + "选择了您的商品(" + orderBase.getTitle() + ")，等待付款中";
		if (OrderBasePayTypeDictEnum.ONDELIVERY.getCode() == orderBase.getPayType()) {
			tips = "用户" + nick + "选购了您的服务(" + orderBase.getTitle() + ")，货到付款，请准备提供服务";
		} else {
			tips = "用户" + nick + "选择了您的商品(" + orderBase.getTitle() + ")，等待付款中";
		}
		pushLogVo.setTitle("订单通知");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		this.doPush(pushLogVo);
	}

	@Override
	public void orderPayed(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);

		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<String> registrationIds = new ArrayList<String>(1);
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		StringBuffer sb = new StringBuffer();
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			sb.append(";");
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					String registrationId = pushAudienceService.getRegistrationIdByUserId(orderSplit2.getSellerId());
					if (StringUtil.isNotBlank(registrationId)) {
						sb.append(orderSplit2.getSellerId().toString()).append(";");
						registrationIds.add(registrationId);
					}
				}
			}
		}

		if (orderBase == null || registrationIds == null || registrationIds.size() == 0) {
			return;
		}

		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_PAYED.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_PAYED.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERSUPPLYS, sb.toString());
		pushLogVo.setMapExtras(mapExtras);
		String nick = "";
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		pushLogVo.setTitle("订单付款通知");
		pushLogVo.setAlert("用户" + nick + "已付款，请查看订单并及时操作");
		pushLogVo.setMessage("用户" + nick + "已付款，请查看订单并及时操作");
		this.doPush(pushLogVo);
	}

	@Override
	public void sendOrderWhenPayed(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		String strUserId = "0";
		List<String> registrationIds = new ArrayList<String>(1);
		SendDeliveryUserOrder sendDeliveryUserOrder = sendDeliveryUserOrderService.getByOrderNo(orderNo);
		if (sendDeliveryUserOrder != null && sendDeliveryUserOrder.getDeliveryUserId() != null
				&& sendDeliveryUserOrder.getDeliveryUserId().intValue() != 0) {
			strUserId = "" + sendDeliveryUserOrder.getDeliveryUserId();
			String registrationId = pushAudienceService
					.getRegistrationIdByUserId(sendDeliveryUserOrder.getDeliveryUserId());
			if (StringUtil.isNotBlank(registrationId)) {
				registrationIds.add(registrationId);
			}
		}

		if (registrationIds == null || registrationIds.size() == 0) {
			return;
		}

		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.SEND_ORDER_NOTIFY.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.SEND_ORDER_NOTIFY.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHSENDORDERUSERID, strUserId);
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setTitle("订单配送通知");
		pushLogVo.setAlert("您有新订单等待配送");
		pushLogVo.setMessage("您有新订单等待配送");
		this.doPush(pushLogVo);
	}

	@Override
	public void orderCancel(String orderNo, OrderBaseOrderStatusCancelTypeDictEnum orderBaseOrderStatusCancelType) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<String> registrationIds = new ArrayList<String>();
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					String registrationId = pushAudienceService.getRegistrationIdByUserId(orderSplit2.getSellerId());
					if (StringUtil.isNotBlank(registrationId)) {
						registrationIds.add(registrationId);
					}
				}
			}
		}
		if (registrationIds == null || registrationIds.size() == 0) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_CANCEL_BUYER.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_CANCEL_BUYER.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		pushLogVo.setMapExtras(mapExtras);
		String tips = "订单(" + orderNo + ")超过"
				+ orderSysParamCache.get(OrderConst.DICTYPE_ORDER_ONLINE_PAY_AUTO_EXPIRE_MINS, "30") + "分钟未支付，已自动取消";
		if (!OrderBaseOrderStatusCancelTypeDictEnum.AUTO.equals(orderBaseOrderStatusCancelType)) {
			String nick = "";
			UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
			if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
				nick = userBase.getNick();
			}
			tips = "用户" + nick + "已取消订单";
		}
		pushLogVo.setTitle("订单取消通知");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		this.doPush(pushLogVo);
	}

	@Override
	public void sellerCancel(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		String registrationId = pushAudienceService.getRegistrationIdByUserId(orderBase.getBuyerId());
		if (StringUtil.isBlank(registrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_CANCEL_SELLER.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		List<String> registrationIds = new ArrayList<String>(1);
		registrationIds.add(registrationId);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_CANCEL_SELLER.getCode());
		// mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBASE,
		// JsonUtil.toJson(orderBase));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		pushLogVo.setMapExtras(mapExtras);
		String nick = "";
		if (orderBase.getSellerId() != null && orderBase.getSellerId().intValue() != 0) {
			UserBase userBase = userBaseService.getById(orderBase.getSellerId());
			if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
				nick = userBase.getNick();
			}
		}
		pushLogVo.setTitle("卖家取消订单通知");
		pushLogVo.setAlert("卖家" + nick + "已取消订单，请留意订单和查收账户余额");
		pushLogVo.setMessage("卖家" + nick + "已取消订单，请留意订单和查收账户余额");
		this.doPush(pushLogVo);
	}

	@Override
	public void orderSent(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		String registrationId = pushAudienceService.getRegistrationIdByUserId(orderBase.getBuyerId());
		if (StringUtil.isBlank(registrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_SENTED.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		List<String> registrationIds = new ArrayList<String>(1);
		registrationIds.add(registrationId);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_SENTED.getCode());
		// mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBASE,
		// JsonUtil.toJson(orderBase));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		pushLogVo.setMapExtras(mapExtras);
		String nick = "";
		if (orderBase.getSellerId() != null && orderBase.getSellerId().intValue() != 0) {
			UserBase userBase = userBaseService.getById(orderBase.getSellerId());
			if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
				nick = userBase.getNick();
			}
		}
		String tips = "卖家" + nick + "已发货，请查看订单信息";
		if (OrderBaseOrderTypeDictEnum.HOMEMAKING.getCode() == orderBase.getOrderType().intValue()) {
			String title = "";
			if (StringUtil.isNotBlank(orderBase.getTitle())) {
				title = orderBase.getTitle();
			}
			tips = "已完成了您下单的" + title + "项目，请签收并对服务人员评价，谢谢支持！";
		}
		pushLogVo.setTitle("卖家发货通知");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		this.doPush(pushLogVo);
	}

	@Override
	public void orderSigned(String orderNo, OrderBaseDeliveryStatusSignTypeDictEnum orderBaseDeliveryStatusSignType) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);

		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<String> registrationIds = new ArrayList<String>();
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					String registrationId = pushAudienceService.getRegistrationIdByUserId(orderSplit2.getSellerId());
					if (StringUtil.isNotBlank(registrationId)) {
						registrationIds.add(registrationId);
					}
				}
			}
		}

		if (orderBase == null || registrationIds == null || registrationIds.size() == 0) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_SIGNED.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_SIGNED.getCode());
		// mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBASE,
		// JsonUtil.toJson(orderBase));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		pushLogVo.setMapExtras(mapExtras);
		String tips = "订单(" + orderNo + ")超过了"
				+ orderSysParamCache.get(OrderConst.DICTYPE_ORDER_ONLINE_RECEIVE_AUTO_EXPIRE_DAYS, "7")
				+ "天未确认收货，已自动签收";
		if (!OrderBaseDeliveryStatusSignTypeDictEnum.AUTOSIGNED.equals(orderBaseDeliveryStatusSignType)) {
			String nick = "";
			UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
			if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
				nick = userBase.getNick();
			}
			tips = "买家" + nick + "已签收，款项已打到您的账户金额";
			if (OrderBaseOrderTypeDictEnum.HOMEMAKING.getCode() == orderBase.getOrderType().intValue()) {
				tips = "客户" + nick + "已确定了您的服务订单，请查看订单信息和账户余额！";
			}
		}
		pushLogVo.setTitle("订单签收通知");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		this.doPush(pushLogVo);
	}

	@Override
	public void applyReturn(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);

		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<String> registrationIds = new ArrayList<String>();
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					String registrationId = pushAudienceService.getRegistrationIdByUserId(orderSplit2.getSellerId());
					if (StringUtil.isNotBlank(registrationId)) {
						registrationIds.add(registrationId);
					}
				}
			}
		}

		if (orderBase == null || registrationIds == null || registrationIds.size() == 0) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_APPLYRETURN.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_APPLYRETURN.getCode());
		// mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBASE,
		// JsonUtil.toJson(orderBase));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		pushLogVo.setMapExtras(mapExtras);
		String nick = "";
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		pushLogVo.setTitle("退货(退款)通知");
		pushLogVo.setAlert("用户" + nick + "申请退货，请查看订单并及时处理");
		pushLogVo.setMessage("用户" + nick + "申请退货，请查看订单并及时处理");
		this.doPush(pushLogVo);
	}

	@Override
	public void returned(String orderNo, OrderBaseReturnStatusCompleteTypeDictEnum orderBaseReturnStatusCompleteType) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		String registrationId = pushAudienceService.getRegistrationIdByUserId(orderBase.getBuyerId());
		if (StringUtil.isBlank(registrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ORDER_RETURNED.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 2);
		List<String> registrationIds = new ArrayList<String>(1);
		registrationIds.add(registrationId);
		pushLogVo.setRegistrationIds(registrationIds);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ORDER_RETURNED.getCode());
		// mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBASE,
		// JsonUtil.toJson(orderBase));
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERNO, orderNo);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHORDERBIZZTYPE,
				"" + (orderBase.getOrderType() == null ? "" : orderBase.getOrderType()));
		pushLogVo.setMapExtras(mapExtras);
		String tips = "订单(" + orderNo + ")已超过"
				+ orderSysParamCache.get(OrderConst.DICTYPE_ORDER_ONLINE_REFUND_AUTO_EXPIRE_DAYS, "3")
				+ "天未处理退款，已自动退款退货";
		if (!OrderBaseReturnStatusCompleteTypeDictEnum.AUTORETURNED.equals(orderBaseReturnStatusCompleteType)) {
			String nick = "";
			if (orderBase.getSellerId() != null && orderBase.getSellerId().intValue() != 0) {
				UserBase userBase = userBaseService.getById(orderBase.getSellerId());
				if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
					nick = userBase.getNick();
				}
			}
			tips = "卖家" + nick + "已同意退货，请留意订单和查收账户余额";
		}
		pushLogVo.setTitle("退货(退款)通知");
		pushLogVo.setAlert(tips);
		pushLogVo.setMessage(tips);
		this.doPush(pushLogVo);
	}

	@Override
	public void pubPraise(Integer userId, Integer beUserId) {
		if (beUserId == null || beUserId.intValue() == 0) {
			return;
		}
		if (userId.intValue() == beUserId.intValue()) {
			return;
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(beUserId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.PRAISED.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.PRAISED.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID, "" + beUserId);// 被推送的人的userId
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		pushLogVo.setTitle("有新点赞");
		pushLogVo.setAlert("有人点赞了您的内容");
		pushLogVo.setMessage("有人点赞了您的内容");
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void pubComment(Integer userId, Integer beUserId, Integer commentId) {
		if (beUserId == null || beUserId.intValue() == 0) {
			return;
		}
		if (userId.intValue() == beUserId.intValue()) {
			return;
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(beUserId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.COMMENTED.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.COMMENTED.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHCOMMENTID, "" + commentId);// 推送的评论id【主键,用于前端展示时定位这条评论】
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID, "" + beUserId);// 被推送的人的userId
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		pushLogVo.setTitle("有新评论");
		pushLogVo.setAlert("有人评论了您的内容");
		pushLogVo.setMessage("有人评论了您的内容");
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void pubUserTopic(Integer userId) {
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.USERTOPIC_UPDATE.getCode());
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USERTOPIC_UPDATE.getCode());
		if (userId == null || userId.intValue() == 0) {
			return;
		}
		List<Integer> friendIds = userFriendService.queryMyFriendIds(userId);
		if (friendIds == null || friendIds.size() == 0) {
			return;
		}
		List<Integer> newFriendIds = new ArrayList<Integer>(friendIds.size());
		for (Integer eId : friendIds) {
			if (userId.intValue() != eId.intValue()) {
				newFriendIds.add(eId);
			}
		}
		List<String> registrationIds = pushAudienceService.getRegistrationIdsByUserIds(newFriendIds);
		if (registrationIds == null || registrationIds.size() == 0) {
			return;
		}
		pushLogVo.setRegistrationIds(registrationIds);
		UserBase userBase = userBaseService.getById(userId);
		if (userBase == null) {
			return;
		}
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_NEWUSERTOPICLOGO, userBase.getFileDomain() + userBase.getLogo());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_NEWUSERTOPICNICK, userBase.getNick());
		pushLogVo.setTitle("有新友事");
		pushLogVo.setAlert("您的朋友发布了新事儿");
		pushLogVo.setMessage("您的朋友发布了新事儿");
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setUserIds(userId.toString());
		this.doPush(pushLogVo);
	}

	@Override
	public void applyFriend(Integer friendId) {
		if (friendId == null || friendId.intValue() == 0) {
			return;
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(friendId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.USER_ADDED_FRIEND.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USER_ADDED_FRIEND.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID, "" + friendId);// 被推送的人的userId
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		pushLogVo.setTitle("消息通知");
		pushLogVo.setAlert("新好友申请，请在圈圈的消息页面查看");
		pushLogVo.setMessage("新好友申请，请在圈圈的消息页面查看");
		pushLogVo.setUserIds(friendId.toString());
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}

	private Result doPush(PushLogVo pushLogVo) {
		Result result = new Result();
		Integer isOpen = pushSysParamCache.getInt(PushConst.PARAMKEY_PUSH_ISOPEN, 1);
		if (isOpen != null && YesNoEnum.NO.getCode() == isOpen.intValue()) {
			result.addErr("圈圈平台已关闭推送服务");
			return result;
		}
		PushLog pushLog = pushLogVo;
		pushLog.setId(null);
		result = pushJgService.sendPush(pushLogVo);
		String msgId = (String) result.get("msgId");
		if (StringUtil.isNotBlank(msgId)) {
			pushLog.setMsgId(msgId);
		}
		pushLog.setNotNull(pushLog);
		pushLogDao.insert(pushLog);
		return result;
	}

	@Override
	public void reply2Comment(Integer userId, Integer beUserId, Integer commentId) {
		if (beUserId == null || beUserId.intValue() == 0) {
			return;
		}
		if (userId.intValue() == beUserId.intValue()) {
			return;
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(beUserId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.REPLY2COMMENTED.getCode());// 有人回复了我的评论
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.REPLY2COMMENTED.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHCOMMENTID, "" + commentId);// 推送的评论id【主键,用于前端展示时定位这条评论】
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID, "" + beUserId);// 被推送的人的userId
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		pushLogVo.setTitle("评论有新的回复");
		pushLogVo.setAlert("有人回复了您的评论");
		pushLogVo.setMessage("有人回复了您的评论");
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void beApplyedCircle(Integer beApplyedId, String circleName) {
		if (beApplyedId == null || beApplyedId.intValue() == 0) {
			return;
		}
		if (StringUtil.isBlank(circleName)) {
			circleName = "圈子";
		}
		String strRegistrationId = pushAudienceService.getRegistrationIdByUserId(beApplyedId);
		if (StringUtil.isBlank(strRegistrationId)) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.USER_BEAPPLYED_CIRCLE.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.USER_BEAPPLYED_CIRCLE.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_USER_BEINVITED_CIRCLENAME, "" + circleName);
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID, "" + beApplyedId);// 被推送的人的userId
		pushLogVo.setStrRegistrationIds(strRegistrationId);
		pushLogVo.setTitle("消息通知");
		pushLogVo.setAlert("有人申请加入你的圈子，请在圈圈的消息页面查看");
		pushLogVo.setMessage("有人申请加入你的圈子，请在圈圈的消息页面查看");
		pushLogVo.setUserIds(beApplyedId.toString());
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}

	@Override
	public void couponNotice(List<Integer> userIds, String msg) {
		if (StringUtil.isBlank(msg)) {
			return;
		}
		if (CollectionUtils.isEmpty(userIds)) {
			return;
		}
		List<String> strRegistrationIds = pushAudienceService.getRegistrationIdsByUserIds(userIds);
		if (CollectionUtils.isEmpty(strRegistrationIds)) {
			return;
		}
		StringBuilder targetRegistrationId = new StringBuilder();
		for (String registrationId : strRegistrationIds) {
			targetRegistrationId.append(";").append(registrationId);
		}
		targetRegistrationId.append(";");
		StringBuilder targetUserIds = new StringBuilder();
		for (Integer userId : userIds) {
			targetUserIds.append(";").append(userId.toString());
		}
		targetUserIds.append(";");
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.COUPON_NOTICE_COMMON.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.COUPON_NOTICE_COMMON.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID,
				"" + (targetUserIds.length() > 0 ? targetUserIds.substring(1) : targetUserIds.toString()));// 被推送的人的userId
		pushLogVo.setStrRegistrationIds((targetRegistrationId.length() > 0 ? targetRegistrationId.substring(1)
				: targetRegistrationId.toString()));
		pushLogVo.setTitle(PushBizzEnum.COUPON_NOTICE_COMMON.getDesc());
		pushLogVo.setUserIds((targetUserIds.length() > 0 ? targetUserIds.substring(1) : targetUserIds.toString()));
		pushLogVo.setAlert(msg);
		pushLogVo.setMessage(msg);
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void shopNotice(String title, String msg, String url, Integer shopId, Integer communityId) {
		if (StringUtil.isBlank(title) || StringUtil.isBlank(msg) || shopId == null) {
			return;
		}
		PushLogVo pushLogVo = new PushLogVo();
		if (communityId != null && communityId.intValue() != 0) {
			pushLogVo.setCommunityId(communityId);
			pushLogVo.setTags("" + communityId);
			List<String> tagValues = new ArrayList<String>(1);
			tagValues.add("" + communityId);
			pushLogVo.setTagValues(tagValues);
		}
		pushLogVo.setPushBizz(PushBizzEnum.SHOP_OPEN.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.SHOP_OPEN.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_TITLE, title.trim());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_MSG, msg.trim());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHSHOPID, shopId.toString());
		if (StringUtil.isNotBlank(url)) {
			mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ_URL, url);
		}
		pushLogVo.setTitle(title);
		pushLogVo.setAlert(title);
		pushLogVo.setMessage(msg);
		pushLogVo.setMapExtras(mapExtras);
		this.doPush(pushLogVo);
	}

	@Override
	public void circleActivityNotice(List<Integer> userIds, Integer activityId, String msg) {
		if (StringUtil.isBlank(msg)) {
			return;
		}
		if (CollectionUtils.isEmpty(userIds)) {
			return;
		}
		if (activityId == null) {
			return;
		}
		List<String> strRegistrationIds = pushAudienceService.getRegistrationIdsByUserIds(userIds);
		if (CollectionUtils.isEmpty(strRegistrationIds)) {
			return;
		}
		StringBuilder targetRegistrationId = new StringBuilder();
		for (String registrationId : strRegistrationIds) {
			targetRegistrationId.append(";").append(registrationId);
		}
		StringBuilder targetUserIds = new StringBuilder();
		;
		for (Integer userId : userIds) {
			targetUserIds.append(";").append(userId.toString());
		}
		PushLogVo pushLogVo = new PushLogVo();
		pushLogVo.setPushBizz(PushBizzEnum.ACTIVITY_OPEN.getCode());
		pushLogVo.setTimeToLive(60 * 60 * 24 * 10);
		pushLogVo.setType(PushTypeEnum.ALERTNMESSAGE.getCode());
		Map<String, String> mapExtras = new HashMap<String, String>();
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_PUSHBIZZ, "" + PushBizzEnum.ACTIVITY_OPEN.getCode());
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHUSERID,
				(targetUserIds.length() > 0 ? targetUserIds.substring(1) : targetUserIds.toString()));// 被推送的人的userId
		mapExtras.put(PushConst.MAPKEY_PUSH_MAPEXTRAS_BEPUSHACTIVITYID, activityId.toString());
		pushLogVo.setStrRegistrationIds((targetRegistrationId.length() > 0 ? targetRegistrationId.substring(1)
				: targetRegistrationId.toString()));
		pushLogVo.setTitle(PushBizzEnum.ACTIVITY_OPEN.getDesc());
		pushLogVo.setUserIds((targetUserIds.length() > 0 ? targetUserIds.substring(1) : targetUserIds.toString()));
		pushLogVo.setAlert(msg);
		pushLogVo.setMessage(msg);
		pushLogVo.setMapExtras(mapExtras);
		pushLogVo.setType(PushTypeEnum.MESSAGE.getCode());
		this.doPush(pushLogVo);
		pushLogVo.setType(PushTypeEnum.ALERT.getCode());
		this.doPush(pushLogVo);
	}
}